<?php

namespace common\models\Activity;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Activity\Activity;

/**
 * ActivitySearch represents the model behind the search form about `common\models\Activity\Activity`.
 */
class ActivitySearch extends Activity
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['ac_id', 'ac_status', 'ac_display','la_id','g_id','cu_id'], 'integer'],
            [['ac_name','ac_cost','ac_desciption', 'start_time', 'end_time', 'ac_man', 'ac_baoming','ac_phone', 'ac_number', 'ac_arrange', 'ac_field', 'ac_sponsor'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Activity::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'ac_id' => $this->ac_id,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'ac_status' => $this->ac_status,
            'ac_display' => $this->ac_display,
            'la_id' => $this->la_id,
            'g_id'=>$this->g_id,
			'cu_id'=>$this->cu_id,
        ]);


        $query->andFilterWhere(['like', 'ac_name', $this->ac_name])
         
            ->andFilterWhere(['like', 'ac_desciption', $this->ac_desciption])
            ->andFilterWhere(['like', 'ac_man', $this->ac_man])
            ->andFilterWhere(['like', 'ac_phone', $this->ac_phone])
            ->andFilterWhere(['like', 'ac_number', $this->ac_number])
            ->andFilterWhere(['like', 'ac_arrange', $this->ac_arrange])
            ->andFilterWhere(['like', 'ac_field', $this->ac_field])
            ->andFilterWhere(['like', 'ac_sponsor', $this->ac_sponsor])
            ->andFilterWhere(['like', 'ac_baoming', $this->ac_baoming])
			->andFilterWhere(['like', 'ac_cost', $this->ac_cost]);

        return $dataProvider;
    }

    /**
     * 进行中
     */
     
    public function checksearch($params)

    {
        $time = time();
        $query = Activity::find()->andWhere(['ac_status'=>Activity::ACSTATUS_ACTIVE])->andWhere(['ac_display'=>Activity::DIS_DELETED])->andWhere(['<','start_time',$time])->andWhere(['>','end_time',$time])->orderBy('ac_id desc');

        // echo "<pre>";
        // var_dump($query);die();
        // echo "</pre>";
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'ac_id' => $this->ac_id,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'ac_status' => $this->ac_status,
            'ac_display' => $this->ac_display,
            'la_id' => $this->la_id,
            'g_id'=>$this->g_id,
			'cu_id'=>$this->cu_id,
        ]);

       $query->andFilterWhere(['like', 'ac_name', $this->ac_name])

            ->andFilterWhere(['like', 'ac_desciption', $this->ac_desciption])
            ->andFilterWhere(['like', 'ac_man', $this->ac_man])
            ->andFilterWhere(['like', 'ac_phone', $this->ac_phone])
            ->andFilterWhere(['like', 'ac_number', $this->ac_number])
            ->andFilterWhere(['like', 'ac_arrange', $this->ac_arrange])
            ->andFilterWhere(['like', 'ac_field', $this->ac_field])
            ->andFilterWhere(['like', 'ac_sponsor', $this->ac_sponsor])
            ->andFilterWhere(['like', 'ac_baoming', $this->ac_baoming])
			->andFilterWhere(['like', 'ac_cost', $this->ac_cost]);

        return $dataProvider;
    }
        /**
     * Creates data provider instance with search query applied
     *
     * @param 已结束
     *
     * @return ActiveDataProvider
     */
    public function unchecksearch($params)
    {
         $time = time();

       
        $query = Activity::find()->andWhere(['ac_status'=>Activity::ACSTATUS_ACTIVE])->andWhere(['ac_display'=>Activity::DIS_SUCCESS])->andWhere(['<','end_time',$time])->orderBy('ac_id desc');
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'ac_id' => $this->ac_id,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'ac_status' => $this->ac_status,
            'ac_display' => $this->ac_display,
            'la_id' => $this->la_id,
            'g_id'=>$this->g_id,
			'cu_id'=>$this->cu_id,
        ]);

      $query->andFilterWhere(['like', 'ac_name', $this->ac_name])

            ->andFilterWhere(['like', 'ac_desciption', $this->ac_desciption])
            ->andFilterWhere(['like', 'ac_man', $this->ac_man])
            ->andFilterWhere(['like', 'ac_phone', $this->ac_phone])
            ->andFilterWhere(['like', 'ac_number', $this->ac_number])
            ->andFilterWhere(['like', 'ac_arrange', $this->ac_arrange])
            ->andFilterWhere(['like', 'ac_field', $this->ac_field])
            ->andFilterWhere(['like', 'ac_sponsor', $this->ac_sponsor])
            ->andFilterWhere(['like', 'ac_baoming', $this->ac_baoming])
			->andFilterWhere(['like', 'ac_cost', $this->ac_cost]);


        return $dataProvider;
    }
            /**
     * Creates data provider instance with search query applied
     *
     * @param array 未进行
     *
     * @return ActiveDataProvider
     */
    public function waitchecksearch($params)
    {
         $time = time();
        $query = Activity::find()->andWhere(['ac_status'=>Activity::ACSTATUS_ACTIVE])->andWhere(['ac_display'=>Activity::DIS_ACTIVE])->andWhere(['>','start_time',$time])->orderBy('ac_id desc');
        //var_dump($query);die();
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'ac_id' => $this->ac_id,
            'start_time' => $this->start_time,
            'end_time' => $this->end_time,
            'ac_status' => $this->ac_status,
            'ac_display' => $this->ac_display,
            'la_id' => $this->la_id,
            'g_id'=>$this->g_id,
			'cu_id'=>$this->cu_id,
        ]);

        $query->andFilterWhere(['like', 'ac_name', $this->ac_name])

            ->andFilterWhere(['like', 'ac_desciption', $this->ac_desciption])
            ->andFilterWhere(['like', 'ac_man', $this->ac_man])
            ->andFilterWhere(['like', 'ac_phone', $this->ac_phone])
            ->andFilterWhere(['like', 'ac_number', $this->ac_number])
            ->andFilterWhere(['like', 'ac_arrange', $this->ac_arrange])
            ->andFilterWhere(['like', 'ac_field', $this->ac_field])
            ->andFilterWhere(['like', 'ac_sponsor', $this->ac_sponsor])
            ->andFilterWhere(['like', 'ac_baoming', $this->ac_baoming])
			->andFilterWhere(['like', 'ac_cost', $this->ac_cost]);


        return $dataProvider;
    }
}
